package net.lzzy.practices.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author liaodcc on 2022/5/12 9:38.
 */
public class StringUtils {
    public static String md5Encode(String origin,String salt){
        try{
            MessageDigest digest = MessageDigest.getInstance("MD5");
            if (salt != null && salt.length() > 0){
                origin += salt;
            }
            digest.update(origin.getBytes());
            byte[] bytes = digest.digest();
            int i = 0;
            StringBuilder builder = new StringBuilder();
            for (byte b : bytes){
                i = b;
                if(i<0){
                    i += 256;
                }
                if (i < 16){
                    builder.append("0");
                }
                builder.append(Integer.toHexString(i));
            }
            return builder.toString();
        }catch (NoSuchAlgorithmException e){
            e.printStackTrace();
            return null;
        }
    }
    public static boolean isEmpty(String str){
        return str == null || str.isEmpty();
    }
}
